
package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.modular.system.entity.Kms;
import cn.stylefeng.guns.sys.modular.system.entity.KmsPool;
import cn.stylefeng.guns.sys.modular.system.service.KmsPoolService;
import cn.stylefeng.guns.sys.modular.system.service.KmsService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author YuJiBiao
 * @version: 1.0
 * @Date 2020/7/8 16:30
 **/
@Controller
@RequestMapping("/kmsPool")
public class KmsPoolPageController extends BaseController {

    @Autowired
    KmsPoolService kmsPoolService;

    @Autowired
    KmsService kmsService;

    private String PREFIX = "/modular/system/kmsPool/";



    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String status) {
        //获取分页参数
        Page<Map<String, Object>> mapPage = kmsPoolService.selectKmsPool();
        return LayuiPageFactory.createPageInfo(mapPage);
    }
    /**
     *
     *
     * @author fengshuonan
     * @Date 2018/12/23 4:56 PM
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "kmsPool.html";
    }

    @RequestMapping(value = "/getInfo",method = RequestMethod.POST)
    @ResponseBody
    public String getInfo(@RequestParam String backId) {
        QueryWrapper<KmsPool> srcwrapper = new QueryWrapper<>();
        srcwrapper.eq("back_id",backId);
        KmsPool one = kmsPoolService.getOne(srcwrapper);
        String key = one.getKey();
        String[] split = key.split(",");
        StringBuffer result =new StringBuffer();
        for (String str:split) {
            QueryWrapper<Kms> kmsQuery = new QueryWrapper<>();
            kmsQuery.eq("key_",str);
            Map<String, Object> map = kmsService.getMap(kmsQuery);
            if(map != null) {
                result.append(str).append("   已使用").append("<br>");
            }
            else {
                result.append(str).append("    未使用").append("<br>");
            }
        }
        return result.toString();
    }

}
